window._MAA = {

    initAreaArmy:function(tiledMap){
        for(var key in window._NPCMAP){
            var layerName = "野区_"+key;
            if(tiledMap.getLayer(layerName)){
                _MAP.areaMapArmy[key]=tiledMap.getLayer(layerName);
            }
        }
    },

    initFightAreaArmy:function(tiledMap){
        for(var key in window._MCFC.areaConfig){
            if(tiledMap.getLayer(key)){
                _MAP.fightAreaMapType[key]=tiledMap.getLayer(key);
            }
        }
    },

    //获取当前坐标所在野区
    getCurrentAreaArmy:function(pos){


        for(var key in _MAP.areaMapArmy){

            var layer = _MAP.areaMapArmy[key];

            if(layer.getTileGIDAt(pos)){
                return key ;
            }

        }

        return null;


    },

    //野外遇敌
    touchArmy:function(pos){

        //console.log("是否遇敌:",_MAP.moveStep);

        //_MAP.moveStep++;

         if(_GAMEDATAHELPER.reduceFightStep()){
            console.log("驱妖:"+window.gameData.noFightStep);
        }else{
            _MAP.moveStep++;
        }
		
		var armyArea = _MAA.getCurrentAreaArmy(pos);
		
		if(!_NPCMAP[armyArea]){
			return false;
		}
		
		if(_MAP.moveStep>=_CS.fightStep){
            _MAP.moveStep=0;

            //var areaType = _MAP.getCurrentAreaType(pos);
            //console.log("遇敌:",armyArea,_NPCMAP[armyArea],areaType);
            if(Math.random()>0.5){
                var fightArea = _MAP.getFightAreaName();
                console.log("战斗场景:"+fightArea);
                return _MAP.jumpToChapter(armyArea,fightArea,null);
            }
        }

        return false;

    },
}